package JDBC;

import java.sql.Connection;
import java.sql.PreparedStatement;

/**
 * 指定DELETE 语句
 */
public class JDBCDemo10 {
    public static void main(String[] args) {
        try (Connection connection = DBUtil.getConnection()){
            connection.setAutoCommit(false);

            String sql = "DELETE FROM user WHERE id = ?";
            PreparedStatement ps = connection.prepareStatement(sql);
            ps.setInt(1,1);
            int num = ps.executeUpdate();
            System.out.println(num>0?"删除成功":"删除失败");

            //connection.commit();
            //System.out.println("提交事务");
            connection.rollback();
            System.out.println("回滚事务");
        }catch (Exception e){
            e.printStackTrace();
        }
    }
}
